package com.doit.day05

import com.doit.day01.Person

object _04_小练习 {
  def main(args: Array[String]): Unit = {

    val list: List[Any] = List(1, "zss", 1.5, 2, true, (1, "zss"), new Person())
    //针对每一个元素，我想干这个事   我想把集合中的所有Int类型的值都乘以10返回给我，其他的都不要
//    List(10,20)

    val list2: List[Any] = list.filter(str => str.isInstanceOf[Int])

    val list1: Seq[Int] = list2.map(str => {
        str.asInstanceOf[Int] * 10
    })
    println(list1)

    

    val value: PartialFunction[Any, Int] = new PartialFunction[Any, Int] {
      //这个方法就类似于我们上面写的filter
      override def isDefinedAt(x: Any) = x.isInstanceOf[Int]

      //类似于上面写的map
      override def apply(v1: Any) = v1.asInstanceOf[Int] * 10
    }

    //collect
    val res: List[Int] = list.collect(value)
    println(res)



  }
}
